package com.captain.sort;

import java.util.Arrays;

/**
 * Des: 冒泡排序
 *
 * @author XL
 * @Date 2021/7/23 8:53
 */
public class BubbleSort {

    public static void main(String[] args) {
        int[] arr = new int[]{6, 3, 4, 3, 2, 1};
        int[] sort = bubbleSort(arr);
        System.out.println(Arrays.toString(arr));
    }

    public static int[] bubbleSort(int[] arr) {
        int len = arr.length;

        for (int i = 0; i < len; i++) {
            boolean f = true;
            for (int k = i; k < len; k++) {
                int l = arr[i];
                int r = arr[k];
                if (l > r) {
                    int temp = arr[i];
                    arr[i] = arr[k];
                    arr[k] = temp;
                    f = false;
                }
            }
            if (f) {
                break;
            }
        }
        return arr;
    }

}
